using System;
using System.Collections.Generic;
using UnityEngine;

public class CurrencyPurchaseTab : MonoBehaviour
{
	public GameObject inAppButonPrefab;

	public UITable table;

	public Transform firstObject;

	public UIScrollView view;

	public InAppPurchase.ItemType itemType;

	private List<InAppPurchase.InAppObject> items;

	protected bool isAligned;

	public Transform lastObject;

	public Action<bool> onComplete;

	private void Start()
	{
		items = InAppPurchase.instance.GetItemsForType(itemType);
		int num = 2;
		InAppPurchase.InAppObject item = items[1];
		//foreach (InAppPurchase.InAppObject item in items)
		//{
			GameObject gameObject = NGUITools.AddChild(table.gameObject, inAppButonPrefab);
			gameObject.SetActive(true);
			gameObject.name = num++.ToString();
			CurrencyPurchaseButton component = gameObject.GetComponent<CurrencyPurchaseButton>();
			component.Init(item, this);
			if (firstObject == null)
			{
				firstObject = gameObject.transform;
			}
			lastObject = gameObject.transform;
		//}
		table.Reposition();
		isAligned = false;
	}

	public void CallOnComplete(bool success)
	{
		if (onComplete != null)
		{
			Action<bool> action = onComplete;
			onComplete = null;
			action(success);
		}
	}

	private void OnEnable()
	{
		isAligned = false;
		InAppPurchase.instance.QueryInventory();
	}

	private void Update()
	{
		//if (!isAligned && firstObject != null)
		//{
		//	if (view.canMoveVertically)
		//	{
		//		UITools.AlignToTopOnScroll(firstObject.GetComponent<UIWidget>(), view, 5f);
		//	}
		//	else if (view.canMoveHorizontally)
		//	{
		//		UITools.AlignToLeftOnScroll(firstObject.GetComponent<UIWidget>(), view, 5f);
		//	}
		//	isAligned = true;
		//}
	}
}
